﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SlectedPanel : MonoBehaviour
{
    public Toggle[] toggles;
    public Button okBtn;

    public int key;
    private int tempKey;
    public Text resultTxt;
    public string jiexi;
    public Text jiexiTxt;

    private void Start()
    {
        for (int i = 0; i < toggles.Length; i++)
        {
            int temp = i;
            toggles[i].onValueChanged.AddListener((bool b) => {
                if (toggles[temp].isOn)
                {
                    tempKey = temp;
                }
            });

        }

        okBtn.onClick.AddListener(CheckKey);

        jiexiTxt.text = jiexi;
    }


    private void CheckKey()
    {

        if (tempKey == key)
        {
            
            resultTxt.text = "答题结果：正确  正确答案：" + NumberToLetter(key);
            resultTxt.color = Color.green;
            EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true);
        }
        else
        {
            resultTxt.text = "答题结果：错误  正确答案：" + NumberToLetter(key);
            resultTxt.color = Color.red;
        }


    }

    char NumberToLetter(int number)
    {
        if (number < 0 || number > 25)
        {
            Debug.Log("输入的数字必须在 0 到 25 之间。");
        }
        char[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
        return letters[number];
    }

}
